package com.dongdong.controller;


import com.alibaba.druid.sql.dialect.h2.visitor.H2ASTVisitorAdapter;
import com.dongdong.service.GoodsService;
import com.dongdong.utils.PageBean;
import com.dongdong.utils.PageResult;
import com.dongdong.utils.Result;
import com.dongdong.vo.GoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {


    @Autowired
    private GoodsService goodsService;


    @PostMapping("/addGoods")
    public Result addGoods(@RequestBody GoodsVO goodsVO, HttpServletRequest request) {
        goodsService.addGoods(goodsVO, request);
        return Result.OK();
    }

    /**
     * seller商品管理的分页查询
     * @param goodsVO
     * @return
     */
    @PostMapping("/getGoodsPage")
    public Result getGoodsPage(@RequestBody PageBean<GoodsVO> goodsVO) {
        PageResult<GoodsVO> goodsVOList = goodsService.getGoodsPage(goodsVO);
        return Result.OK().setData(goodsVOList);
    }

    @PutMapping("/updateGoodsStatus")
    public Result updateGoodsStatus(@RequestParam(name = "ids[]") List<Long> ids,@RequestParam String status){

        return goodsService.updateGoodsStatus(ids,status);
    }


    /**
     * 根据商品id查询goodsvo下面的数据
     * @param goodsId
     * @return
     */
    @GetMapping("/getGoodsAndDescAndItem")
    public Result getGoodsAndDescAndItem(@RequestParam Long goodsId){
        GoodsVO goodsVO = goodsService.getGoodsAndDescAndItem(goodsId);
        return Result.OK().setData(goodsVO);
    }
}
